package com.itheima.controller;

import com.itheima.entry.Result;
import com.itheima.pojo.LinkMan;
import com.itheima.service.LinkManService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/linkman")
public class LinkManController {
    @Autowired
    private LinkManService linkManService;

    @RequestMapping("/findAll")
    public Result findAll() {
        List<LinkMan> linkManList = linkManService.findAll();
        Result result = new Result(true, "查询联系人成功!", linkManList);
        return result;
    }

    @RequestMapping("/add")
    public Result add(@RequestBody LinkMan linkMan) {
        try {
            System.out.println(linkMan);
            linkManService.add(linkMan);
            return new Result(true, "添加联系人成功!");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "添加联系人失败!");
        }
    }
}
